﻿using Furion.DynamicApiController;
using IndoorPosition.Server.Core.Utils;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IndoorPosition.Server.Application
{
    /// <summary>
    /// 项目相关服务接口
    /// </summary>
    public class ProjectAppService: IDynamicApiController
    {
        IProjectService _projectService;

        public ProjectAppService(IProjectService projectService)
        {
            _projectService = projectService;
        }

        /// <summary>
        /// 添加项目
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<int> Add(ProjectInputDto input)
        {
            return await _projectService.AddAsync(input);
        }

        /// <summary>
        /// 删除项目
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task Delete(int id)
        {
            await _projectService.DeleteAsync(id);
        }

        /// <summary>
        /// 更新项目信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task Update(ProjectDto input)
        {
            await _projectService.UpdateAsync(input);
        }

        /// <summary>
        /// 分页获取项目信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<PagedList<ProjectDto>> List(PageInputDto input)
        {
            return await _projectService.ListAsync(input);
        }

        /// <summary>
        /// 获取所有的项目
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<List<ProjectDto>> ListAll(SearchInputDto input)
        {
            return await _projectService.ListAllAsync(input);
        }

        public async Task<string> UploadRoute(IFormFile file)
        {
            return await _projectService.UploadRouteAsync(file);
        }

        /// <summary>
        /// 下载路径文件
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> DownloadRoute(string fileName)
        {
            return await _projectService.DownloadRouteAsync(fileName);
        }
    }
}
